<?php
class statistics extends CI_Controller{
	
	public function __construct(){
		parent::__construct();
		
		if (!$this->session->userdata('LoggedIn')){
			redirect('login');
		}else{
			$this->load->model('statisticsmodel', 'statistics', TRUE);
			$this->load->library("pagination");
		}
	}
	
	public function index(){
		$data['id'] = $this->session->userdata('id');
		$data['name'] = $this->session->userdata('name');
		$data['image'] = $this->session->userdata('image');
		$data['date_of_birth'] = $this->session->userdata('date_of_birth');
		$data['role'] = $this->session->userdata('role');
		$data['address'] = $this->session->userdata('address');
		
		$config = array();
        $config["base_url"] = base_url() . "statistics/index";
        $config["total_rows"] = $this->statistics->statistics_count();
        $config["per_page"] = 20;
        $choice = $config["total_rows"] / $config["per_page"];
    	$config["num_links"] = round($choice);
		
		$this->pagination->initialize($config);
 
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->statistics->
            fetch_statistics($config["per_page"], $page);
            
        $data["links"] = $this->pagination->create_links();
 		
		$this->load->view('statistics', $data);
	}
	
	public function view_detail(){
		$data['id'] = $this->session->userdata('id');
		$data['name'] = $this->session->userdata('name');
		$data['image'] = $this->session->userdata('image');
		$data['date_of_birth'] = $this->session->userdata('date_of_birth');
		$data['role'] = $this->session->userdata('role');
		$data['address'] = $this->session->userdata('address');
		
		if (!isset($_GET["id"]) || empty($_GET["id"])){
			redirect("statistics");
		}
		
		$id = $_GET["id"];
		
		$results = $this->statistics->bill_description_detail($id);
		
		$data["results"] = $results;
		
		$this->load->view("viewbilldetail", $data);
		
		
	}
}